package org.bling.star.server.connect;

import org.bling.star.server.connect.node.TalkingStream;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class GlobalPoolManager {
    private static final Map<String, StreamPool> keyLinkedStreams;

    static {
        keyLinkedStreams = new HashMap<>();
    }
    public static StreamPool getFrom(String secretKey) {
        return keyLinkedStreams.get(secretKey);
    }

    public static List<StreamPool> getAll() {
        return keyLinkedStreams.entrySet().stream().map(Map.Entry::getValue).collect(Collectors.toList());
    }

    public static void addPool(TalkingStream talkingStream) {
        keyLinkedStreams.put(talkingStream.getStreamSecretKey().getStreamKey(), talkingStream);
    }
}
